<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
    <LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="White" Offset="0"/>
        <GradientStop Color="#FFE3E5F0" Offset="0.5"/>
        <GradientStop Color="#FFC6C5D7" Offset="1.0"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ExpanderShadowFill" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="Transparent" Offset="0.5"/>
        <GradientStop Color="#30111111" Offset="1"/>
    </LinearGradientBrush>

    <Style x:Key="GroupBoxExpanderToggleButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid SnapsToDevicePixels="False" Background="Transparent">
                        <Ellipse HorizontalAlignment="Center" x:Name="circle" VerticalAlignment="Center" Width="15" Height="15" Fill="{DynamicResource ButtonNormalBackgroundFill}" Stroke="DarkGray"
                                 IsHitTestVisible="False"/>
                        <Ellipse Visibility="Hidden" HorizontalAlignment="Center" x:Name="shadow" VerticalAlignment="Center" Width="13" Height="13" Fill="{DynamicResource ExpanderShadowFill}"
                                 IsHitTestVisible="False"/>
                        <Path SnapsToDevicePixels="false" x:Name="arrow" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="#666" StrokeThickness="2" Data="M1,1 L4,4 7,1" 
                              IsHitTestVisible="False"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Data" TargetName="arrow" Value="M 1,4  L 4,1  L 7,4"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Stroke" TargetName="circle" Value="#666"/>
                            <Setter Property="Stroke" TargetName="arrow" Value="#222"/>
                            <Setter Property="Visibility" TargetName="shadow" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <SolidColorBrush x:Key="GroupBoxBorderBrush" Color="#D0D0BF"/>
    <SolidColorBrush x:Key="GroupBoxHeaderBrush" Color="#0046D5"/>
    <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>
    
    <Style TargetType="Expander">
        <Setter Property="BorderBrush" Value="{StaticResource GroupBoxBorderBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Margin" Value="0,0,0,5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="6" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="6" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="6" />
                        </Grid.RowDefinitions>
                        <Border x:Name="OuterBorder" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="4" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Transparent" Background="{TemplateBinding Background}" />
                        <Border x:Name="Header" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Padding="3,0,3,0" Background="Transparent">
                            <Grid SnapsToDevicePixels="False" Background="Transparent" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <ToggleButton Grid.Column="0" MinHeight="0" MinWidth="0"
                                    Name="HeaderToggle" Style="{StaticResource GroupBoxExpanderToggleButtonStyle}"
                                    IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" >
                                </ToggleButton>
                                <ContentPresenter ContentSource="Header" RecognizesAccessKey="true"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3,0,0,0" />
                            </Grid>
                        </Border>

                        <ContentPresenter x:Name="ExpandSite" Visibility="Collapsed" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <ContentPresenter.LayoutTransform>
                                <TranslateTransform Y="200" X="-300"/>
                            </ContentPresenter.LayoutTransform>
                        </ContentPresenter>

                        <Border Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="4" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="4">
                            <Border.OpacityMask>
                                <MultiBinding Converter="{StaticResource BorderGapMaskConverter}" ConverterParameter="7">
                                    <Binding Path="ActualWidth" ElementName="Header"/>
                                    <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
                                    <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
                                </MultiBinding>
                            </Border.OpacityMask>
                        </Border>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="true">
                            <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <!--EventTrigger RoutedEvent="Expander.Expanded">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Height" From="0" To="400" BeginTime="0:0:0" Duration="0:0:1">
                                    <DoubleAnimation Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TranslateTransform.Y)" From="-400" To="0" BeginTime="0:0:0" Duration="0:0:1"/>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Height" BeginTime="0:0:0" Duration="0:0:1">
                                        <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                                        <SplineDoubleKeyFrame KeyTime="0:0:1" Value="Auto"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <!-SizeAnimation Duration="1" BeginTime="0:0:0"/>
                                    <DoubleAnimation From="0" To="400" Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Height" Duration="0:0:1"/->
                                    <!-ColorAnimation To="Red" Storyboard.TargetName="Header" Storyboard.TargetProperty="Background" Duration="0:0:1"/>
                                    (FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)
                                    <ColorAnimation To="Red" Storyboard.TargetName="OuterBorder" Storyboard.TargetProperty="Background" Duration="0:0:1"/->
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    
    <Style x:Key="HorizontalGroupBoxExpanderToggleButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid SnapsToDevicePixels="False" Background="Transparent">
                        <Ellipse HorizontalAlignment="Center" x:Name="circle" VerticalAlignment="Center" Width="15" Height="15" Fill="{DynamicResource ButtonNormalBackgroundFill}" Stroke="DarkGray"/>
                        <Ellipse Visibility="Hidden" HorizontalAlignment="Center" x:Name="shadow" VerticalAlignment="Center" Width="13" Height="13" Fill="{DynamicResource ExpanderShadowFill}"/>
                        <Path SnapsToDevicePixels="false" x:Name="arrow" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="#666" StrokeThickness="2" Data="M1,1 L4,4 1,7" />
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Data" TargetName="arrow" Value="M 4,1  L 1,4  L 4,7"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Stroke" TargetName="circle" Value="#666"/>
                            <Setter Property="Stroke" TargetName="arrow" Value="#222"/>
                            <Setter Property="Visibility" TargetName="shadow" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <SolidColorBrush x:Key="ExpanderBackground" Color="#efefef" />
    <SolidColorBrush x:Key="ExpanderHeader" Color="#FFE5ECFF" />
    <Style x:Key="HorizontalExpander" TargetType="{x:Type Expander}">
        <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}" />
        <Setter Property="Margin" Value="0,0,5,0" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Border x:Name="OuterBorder" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{StaticResource ExpanderBackground}" HorizontalAlignment="Left"  Margin="{TemplateBinding Margin}">
                        <Grid SnapsToDevicePixels="true">
                          <Grid.RowDefinitions>
                              <RowDefinition Height="Auto" />
                              <RowDefinition Height="*" />
                          </Grid.RowDefinitions>
                          <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" x:Name="LeftCol" />
                            <ColumnDefinition Width="32" x:Name="RightCol" />
                          </Grid.ColumnDefinitions>
                          
                          <Border x:Name="Header" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0,0,0,1" BorderBrush="{TemplateBinding BorderBrush}" Background="{StaticResource ExpanderHeader}" />
                                    
                          <ContentPresenter x:Name="hdrPresenter" Grid.Row="1" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="true"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0" Width="Auto">
                               <ContentPresenter.LayoutTransform>
                                   <RotateTransform Angle="270" />
                               </ContentPresenter.LayoutTransform>
                           </ContentPresenter>
                           <ToggleButton Grid.Row="0" Grid.Column="1" MinHeight="0" MinWidth="0" HorizontalAlignment="Right" Margin="8,4,8,4"
                                        x:Name="HeaderToggle" Style="{StaticResource HorizontalGroupBoxExpanderToggleButtonStyle}"
                                        IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" >
                           </ToggleButton>
                           <ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="Auto">
                               <ContentPresenter x:Name="ExpandSite" Visibility="Collapsed" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                           </ScrollViewer>
                        </Grid>
                    </Border>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="true">
                            <Setter Property="HorizontalAlignment" TargetName="OuterBorder" Value="Stretch"/>
                            <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                            <Setter Property="Grid.Row" TargetName="hdrPresenter" Value="0"/>
                            <Setter Property="Grid.Column" TargetName="hdrPresenter" Value="0"/>
                            <Setter Property="Margin" TargetName="hdrPresenter" Value="8,0,8,0"/> 
                            <Setter Property="HorizontalAlignment" TargetName="hdrPresenter" Value="Left"/>
                            <Setter Property="Grid.Row" TargetName="ExpandSite" Value="1"/>
                            <Setter Property="Grid.ColumnSpan" TargetName="ExpandSite" Value="2"/>
                            <Setter Property="Width" TargetName="LeftCol" Value="*"/>
                            <Setter Property="ContentPresenter.LayoutTransform" TargetName="hdrPresenter">
                                <Setter.Value>
                                    <RotateTransform Angle="0" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="ButtonlessExpander" TargetType="Expander">
        <Setter Property="Margin" Value="1" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <ContentPresenter x:Name="ExpandSite" Visibility="Collapsed" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="true">
                            <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>